/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.WebIDE.ejb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author huy
 */
@Entity
@Table(name = "users")
@NamedQueries({@NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"), @NamedQuery(name = "Users.findByUserName", query = "SELECT u FROM Users u WHERE u.userName = :userName"), @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password")})
public class Users implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "user_name")
    private String userName;
    @Basic(optional = false)
    @Column(name = "password")
    private String password;
    @JoinTable(name = "users_groups", joinColumns = {@JoinColumn(name = "user_name", referencedColumnName = "user_name")}, inverseJoinColumns = {@JoinColumn(name = "group_name", referencedColumnName = "group_name")})
    @ManyToMany(fetch = FetchType.EAGER)
    private Collection<Groups> groupsCollection;
    @OneToMany(mappedBy = "userName", fetch = FetchType.EAGER)
    private Collection<Projects> projectsCollection;
    @OneToMany(mappedBy = "userName", fetch = FetchType.EAGER)
    private Collection<Topics> topicsCollection;
    @OneToMany(mappedBy = "userName", fetch = FetchType.EAGER)
    private Collection<Replies> repliesCollection;
    @OneToMany(mappedBy = "userName", fetch = FetchType.EAGER)
    private Collection<Messages> messagesCollection;

    public Users() {
    }

    public Users(String userName) {
        this.userName = userName;
    }

    public Users(String userName, String password) {
        this.userName = userName;
        this.password = password;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Collection<Groups> getGroupsCollection() {
        return groupsCollection;
    }

    public void setGroupsCollection(Collection<Groups> groupsCollection) {
        this.groupsCollection = groupsCollection;
    }

    public Collection<Projects> getProjectsCollection() {
        return projectsCollection;
    }

    public void setProjectsCollection(Collection<Projects> projectsCollection) {
        this.projectsCollection = projectsCollection;
    }

    public Collection<Topics> getTopicsCollection() {
        return topicsCollection;
    }

    public void setTopicsCollection(Collection<Topics> topicsCollection) {
        this.topicsCollection = topicsCollection;
    }

    public Collection<Replies> getRepliesCollection() {
        return repliesCollection;
    }

    public void setRepliesCollection(Collection<Replies> repliesCollection) {
        this.repliesCollection = repliesCollection;
    }

    public Collection<Messages> getMessagesCollection() {
        return messagesCollection;
    }

    public void setMessagesCollection(Collection<Messages> messagesCollection) {
        this.messagesCollection = messagesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userName != null ? userName.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.userName == null && other.userName != null) || (this.userName != null && !this.userName.equals(other.userName))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.WebIDE.ejb.entities.Users[userName=" + userName + "]";
    }

}
